<template>
<div class="main">
	<content_top title="系统首页"></content_top>
	
	<div class="main_con" id="main">
		
		
		<div class="total_box">
			<div class="filter_box">
				<currency_filter v-model="bz" field="name" style="width:200px" @change="currency_change"></currency_filter>
				<!--Button @click="z_query">查询</Button-->
			</div>
			<br>
			<div style="margin-bottom: 20px;float:left;width:100%;" v-if="is_priv">
				<div class="item_box" style="width: 24%;margin-right: 1%;">
					<img src="./../../assets/images/hicon1.png">
					<div class="item_box_con">
						<h6>现金总余额</h6>
						<span class="price_box">{{mark}}{{totals.cash}}</span>
					</div>
					
				</div>
				<div class="item_box"  style="width: 24%;margin-right: 1%;">
					<img src="./../../assets/images/hicon2.png">
					<div class="item_box_con">
						<h6>银行总余额</h6>
						<span class="price_box">{{mark}}{{totals.bank}}</span>
					</div>
					
				</div>
				<div class="item_box" style="width: 49%;margin-right: 0;" >
					<img src="./../../assets/images/hicon3.png">
					<div class="item_box_con">
						<h6>业务收入发生额</h6>
						<span class="price_box">{{mark}}{{totals.yewu}}</span>
					</div>
					<div class="item_box_right">
						<div class="box_line">
							<img src="./../../assets/images/hicon8.png">
							<h6>律所代收</h6>
							<span class="price_box">{{mark}}{{totals.lvsuo}}</span>
						</div>
						<div class="box_line">
							<img src="./../../assets/images/hicon9.png">
							<h6>风资各主体</h6>
							<span class="price_box">{{mark}}{{totals.fengzi}}</span>
						</div>
					</div>
				</div>
			</div>
			<div style="margin-bottom: 20px;float:left;width:100%;">
				<div class="item_box" style="width: 24%;margin-right: 1%;">
					<img src="./../../assets/images/hicon4.png">
					<div class="item_box_con">
						<h6>收入预算/实数</h6>
						<span class="price_box">{{mark}}{{srkz.srys}}/{{srkz.srysss}}</span>
					</div>
					
				</div>
				<div class="item_box"  style="width: 24%;margin-right: 1%;">
					<img src="./../../assets/images/hicon5.png">
					<div class="item_box_con">
						<h6>收入差额</h6>
						<span class="price_box">{{mark}}{{srkz.srce}}</span>
					</div>
					
				</div>
				<div class="item_box"  style="width: 24%;margin-right: 1%;">
					<img src="./../../assets/images/hicon6.png">
					<div class="item_box_con">
						<h6>开支预算/实数</h6>
						<span class="price_box">{{mark}}{{srkz.kzys}}/{{srkz.kzysss}}</span>
					</div>
				</div>
				<div class="item_box" style="width: 24%;margin-right: 0;" >
					<img src="./../../assets/images/hicon7.png">
					<div class="item_box_con">
						<h6>开支差额</h6>
						<span class="price_box">{{mark}}{{srkz.kzce}}</span>
					</div>
				</div>
			</div>
		</div>
		
		<div class="company_box" v-show="is_show_company">
			<div class="filter_box">
				<company_list v-model="filter.company" field="sx_name" style="min-width:200px;max-width:400px;" :multiple="true"></company_list>
				<!--bumen_filter v-model="filter.bumen" field="name" style="width:200px;display: inline-block;"></bumen_filter-->
				<Select v-model="filter.bumen" multiple style="width:200px">
			        <Option v-for="item in bumenList" :value="item.value" :key="item.value">{{ item.label }}</Option>
			    </Select>
				<Button @click="query">查询</Button>
			</div>
			<br>
			
			<!--div class="cb_box" v-for="val in company_bumens">
				<div class="box_ti">
					<h3>{{val.company}} {{val.bumen}}</h3>
				</div>
				<div class="box_con">
					<div class="cbbox">
						<p class="top">收入预算/实数</p>
						<p class="bottom">¥50000.00/30000.00</p>
					</div>
					<div class="cbbox">
						<p class="top">收入差额</p>
						<p class="bottom" style="color:#1ABC9C;">¥20000.00</p>
					</div>
					<div class="cbbox">
						<p class="top">开支预算/实数</p>
						<p class="bottom">¥50000.00/70000.00</p>
					</div>
					<div class="cbbox">
						<p class="top">收入差额</p>
						<p class="bottom" style="color:red;">¥20000.00</p>
					</div>
				</div>
			</div-->
			<div class="cb_box" v-for="val in company_bumens">
				<div class="box_ti">
					<h3>{{val.company}} {{val.bumen}}</h3>
				</div>
				<div class="box_con">
					<div class="cbbox">
						<p class="top">收入</p>
						<p class="bottom">{{mark}}{{val.income}}</p>
					</div>
					<div class="cbbox">
						<p class="top">支出</p>
						<p class="bottom" style="color:#1ABC9C;">{{mark}}{{val.expenses}}</p>
					</div>
				</div>
			</div>
			
		</div>
		<div class="company_act">
			<a @click="is_show_company=!is_show_company">{{is_show_company?'点击收起':'点击展开'}}</a>
		</div>
		
		<div class="san_list">
			
			<div class="san_item">
				<div class="box" style="height: 200px;">
					<div class="box_ti">
						<h3>待处理事务</h3>
						
					</div>
					<div class="box_con">
						<ul class="log_list">
							<li>
								<a>待查看公告<span class="datetime">(0)</span></a>
							</li>
							<li>
								<a>待看站内信<span class="datetime">(0)</span></a>
							</li>
							<li> 
								<a @click="$router.push({name:'n_system'})">待查看消息<span class="datetime">({{message.count}})</span></a>
							</li>
						</ul>
					</div>
				</div>
			</div>
			
			<div class="san_item">
				<div class="box" style="height: 200px;">
					<div class="box_ti">
						<h3>快捷入口</h3>
					</div>
					<div class="box_con" style="padding:0px;">
						<ul class="quick_list">
							<li>
								<a v-if="has_cash1_priv" @click="$router.push({name:'c_cash'})">
									<img src="./../../assets/images/kuaijie1.png">
									<p>现金日记账</p>
								</a>
								<a v-else @click="no_priv">
									<img src="./../../assets/images/kuaijie1.png">
									<p>现金日记账</p>
								</a>
							</li>
							<li>
								<a v-if="has_bank1_priv" @click="$router.push({name:'c_bank'})">
									<img src="./../../assets/images/kuaijie2.png">
									<p>银行日记账</p>
								</a>
								<a v-else @click="no_priv">
									<img src="./../../assets/images/kuaijie2.png">
									<p>银行日记账</p>
								</a>
							</li>
							<li>
								<a v-if="has_duizhang1_priv" @click="$router.push({name:'a_accounts'})">
									<img src="./../../assets/images/kuaijie3.png">
									<p>对账处理</p>
								</a>
								<a v-else @click="no_priv">
									<img src="./../../assets/images/kuaijie3.png">
									<p>对账处理</p>
								</a>
							</li>
							<li>
								<a @click="$router.push({name:'my_account'})">
									<img src="./../../assets/images/kuaijie4.png">
									<p>账户设置</p>
								</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
			
		</div>
	</div>
	<div style="height:50px;"></div>
	<div class="msg_box">
		<p>尚未开发！</p>
	</div>
</div>
</template>

<script>
import currency_filter from '@/themes/components/currency_filter';
import company_list from '@/themes/components/company_list';
//import bumen_filter from '@/themes/components/bumen_filter';
import Wcore from '@/libs/common';

export default {
    data () {
        return {
            log_list:[],
			totals:{
				cash:0,
				bank:0,
				yewu:0,
				lvsuo:0,
				fengzi:0,
			},
			srkz:{
				srys:0,
				srysss:0,
				srce:0,
				kzys:0,
				kzysss:0,
				kzce:0
			},
			bz:'人民币',
			mark:'¥',
			is_show_company:true,
			filter:{
				company:'',
				bumen:''
			},
			bumenList:[],
			is_priv:false,
			has_cash1_priv:false,
			has_bank1_priv:false,
			has_duizhang1_priv:false,
			message:{
				count:0,
				list:[]
			},
			company_bumens:[]
        };
    },
    components:{
		currency_filter,
		company_list,
		//bumen_filter
	},
	created(){
		this.load_log_list();
		this.load_total();
		
		try{
			if(this.user){
				var privs = this.user.privs.split(',');
			}
			else{
				var privs = [];
			}
		}
		catch(e){
			var privs = [];
		}
		if(this._checkPriv('chuna|accounting',privs)){
			this.is_priv = true;
		}

		//判断快捷入口是否有权限进入
		//现金日记账
		if(this._checkPriv('chuna_cash_1',privs)){
			this.has_cash1_priv = true;
		}
		//银行日记账
		if(this._checkPriv('chuna_bank_1',privs)){
			this.has_bank1_priv = true;
		}
		//对账处理
		if(this._checkPriv('accounting_duizhang_1',privs)){
			this.has_duizhang1_priv = true;
		}
		
		this.load_msg_type();
		
		
		
	},
	mounted(){
		
	},
	computed:{
		user(){
			var user = this.$store.state.user.user_info;
			this.filter.company = user.company;
			var bumens = user.bumen.split(',');

			var newbumen = new Array();
			for(var i=0;i<bumens.length;i++){
				newbumen.push({'value':bumens[i],'label':bumens[i]});
			}
			this.bumenList = newbumen;
			this.filter.bumen = bumens;
			this.$forceUpdate();

			return user;
		}
	},
    methods: {
		load_log_list(){
			var self = this;
			var postdata = {
				page:1
			};
			Whttp.load('System/Logs/get_list',postdata,function(result){
				self.log_list = result.list;
				
			});
		},
		load_total(){
			var self = this;
			var postdata = {
				bz:this.bz
			};
			Whttp.load('System/Home/get_total',postdata,function(result){
			
				for(var i in self.totals){
					if(result[i]){
						self.totals[i] = result[i];
					}
				}
				self.mark = result.mark;
			});
		},
		query(){

			var self = this;
			var postdata = this.filter;
			
			Whttp.load('System/Home/get_company_bumen',postdata,function(result){
				self.company_bumens = result;
			});
		},
		z_query(){
			this.load_total();
		},
		load_msg_type(){
			var self = this;
			var postdata = {
				
			};
			
			Whttp.load('System/Message/get_new',postdata,function(result){
				self.message.count = parseInt(result.count);
				self.message.list = result.list;
			});
		},
		currency_change(val){
			var self = this;
			setTimeout(function(){
				self.z_query();
			},500);
			
		},
		no_priv(){
			alert('当前账号无权限');
		}
    }
};
</script>

<style scoped >
    @import 'index.css';
</style>